// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MD5Utils.java

package com.ronglian.register_mini_program.util;

import java.util.Random;

import org.apache.commons.codec.digest.DigestUtils;

public class MD5Utils {

    public MD5Utils() {
    }

    public static String getMD5Password(String password) {
        Random r = new Random();
        StringBuilder sb = new StringBuilder(16);
        sb.append(r.nextInt(0x5f5e0ff)).append(r.nextInt(0x5f5e0ff));
        int len = sb.length();
        if (len < 16) {
            for (int i = 0; i < 16 - len; i++)
                sb.append("0");

        }
        String salt = sb.toString();
        password = DigestUtils.md5Hex((new StringBuilder()).append(password).append(salt).toString());
        char cs[] = new char[48];
        for (int i = 0; i < 48; i += 3) {
            cs[i] = password.charAt((i / 3) * 2);
            char c = salt.charAt(i / 3);
            cs[i + 1] = c;
            cs[i + 2] = password.charAt((i / 3) * 2 + 1);
        }

        return new String(cs);
    }

    public static boolean verifyMD5Password(String password, String md5) {
        boolean result;
        try {
            char cs1[] = new char[32];
            char cs2[] = new char[16];
            for (int i = 0; i < 48; i += 3) {
                cs1[(i / 3) * 2] = md5.charAt(i);
                cs1[(i / 3) * 2 + 1] = md5.charAt(i + 2);
                cs2[i / 3] = md5.charAt(i + 1);
            }

            String salt = new String(cs2);
            result = DigestUtils.md5Hex((new StringBuilder()).append(password).append(salt).toString()).equals(new String(cs1));
        } catch (Exception e) {
            return false;
        }
        return result;
    }
}
